﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DigitalHydraParticleEditor
{
    public partial class RandomizeToolBox : Form
    {

        //public event ApplyEventHandler Apply;

        public RandomizeToolBox()
        {
            InitializeComponent();
        }

        private void SelectAllButton_Click(object sender, EventArgs e)
        {
            LifeSpanCheckBox.Checked = true;
            MaxLifeSpan.Checked = true;
            MaxParticleCheckBox.Checked = true;
            StartScaleCheckBox.Checked = true;
            EndScaleCheckBox.Checked = true;
            XVelCheckBox.Checked = true;
            XVel2CheckBox.Checked = true;
            YVelCheckBox.Checked = true;
            YVel2CheckBox.Checked = true;
            RotationCheckBox.Checked = true;
            GravityXCheckBox.Checked = true;
            GravityYCheckBox.Checked = true;
            SourceBlendCheckBox.Checked = true;
            DestBlendCheckBox.Checked = true;
            EmitterWCheckBox.Checked = true;
            EmitterHCheckBox.Checked = true;
            EmitterPosXCheckBox.Checked = true;
            EmitterPosYCheckBox.Checked = true;
            StartAlphaCheckBox.Checked = true;
            EndAlphaCheckBox.Checked = true;
            ParticleStartColorCheckBox.Checked = true;
            ParticleEndColorCheckBox.Checked = true;
        }

        public void Randomize(decimal _MinLifeVal,decimal _MaxLifeVal,decimal _MaxPartVal,decimal _StartScaleVal,
            decimal _EndScaleVal,decimal _XVelVal,decimal _XVelVal2,decimal _YVelVal,decimal _YVelVal2,decimal _RotVal,
            decimal _GravXVal,decimal _GravYVal,string _SrcVal,string _DestVal,decimal _WidthVal,decimal _HeightVal,
            decimal _XVal,decimal _YVal,decimal _StartAVal,decimal _EndAVal,Color _StartColorVal,Color _EndColorVal)
        {

            Random rand = new Random();


            if (MaxLifeSpan.Checked == true)
            {
                _MaxLifeVal = rand.Next(0, 500);
            }
            if (LifeSpanCheckBox.Checked == true)
            {
                _MinLifeVal = rand.Next(0, (int)_MaxLifeVal);
            }
            if (MaxParticleCheckBox.Checked == true)
            {
                _MaxPartVal = rand.Next(0, 1000);
            }
            if (StartScaleCheckBox.Checked == true)
            {
                _StartScaleVal = rand.Next(0, 10);
            }
            if (EndScaleCheckBox.Checked == true)
            {
                _EndScaleVal = rand.Next(0, 10);
            }
            if (XVelCheckBox.Checked == true)
            {
                _XVelVal = rand.Next(0, 100);
            }
            if (XVel2CheckBox.Checked == true)
            {
                _XVelVal2 = rand.Next(-100, 0);
            }
            if (YVelCheckBox.Checked == true)
            {
                _YVelVal = rand.Next(0, 100);
            }
            if (YVel2CheckBox.Checked == true)
            {
                _YVelVal2 = rand.Next(-100, 0);
            }
            if (RotationCheckBox.Checked == true)
            {
                _RotVal = rand.Next(-3600, 3600);
            }
            if (GravityXCheckBox.Checked == true)
            {
                _GravXVal = rand.Next(-100, 100);
            }
            if (GravityYCheckBox.Checked == true)
            {
                _GravYVal = rand.Next(-100, 100);
            }
            if (SourceBlendCheckBox.Checked == true)
            {

                int value = rand.Next(1,17);

                switch (value)
                {
                    case 1:
                        _SrcVal = "ZERO";
                        
                        break;
                    case 2:
                        _SrcVal = "ONE";
                        
                        break;
                    case 3:
                        _SrcVal = "SRCCOLOR";
                        
                        break;
                    case 4:
                        _SrcVal = "INVSRCCOLOR";
                        
                        break;
                    case 5:
                        _SrcVal = "SRCALPHA";
                        
                        break;
                    case 6:
                        _SrcVal = "INVSRCALPHA";
                        
                        break;
                    case 7:
                        _SrcVal = "DESTALPHA";
                        
                        break;
                    case 8:
                        _SrcVal = "INVDESTALPHA";
                       
                        break;
                    case 9:
                        _SrcVal = "DESTCOLOR";
                        
                        break;
                    case 10:
                        _SrcVal = "INVDESTCOLOR";
                        
                        break;
                    case 11:
                        _SrcVal = "SRCALPHASAT";
                        
                        break;
                    case 12:
                        _SrcVal = "BOTHSRCALPHA";
                        
                        break;
                    case 13:
                        _SrcVal = "BOTHINVSRCALPHA";
                        
                        break;
                    case 14:
                        _SrcVal = "BLENDFACTOR";
                        
                        break;
                    case 15:
                        _SrcVal = "INVBLENDFACTOR";
                        
                        break;
                    case 16:
                        _SrcVal = "SRCCOLOR2";
                        
                        break;
                    case 17:
                        _SrcVal = "INVSRCCOLOR2";
                        
                        break;
                };
            }
            if (DestBlendCheckBox.Checked == true)
            {
                int value = rand.Next(1, 17);

                switch (value)
                {
                    case 1:
                        _DestVal = "ZERO";

                        break;
                    case 2:
                        _DestVal = "ONE";

                        break;
                    case 3:
                        _DestVal = "SRCCOLOR";

                        break;
                    case 4:
                        _DestVal = "INVSRCCOLOR";

                        break;
                    case 5:
                        _DestVal = "SRCALPHA";

                        break;
                    case 6:
                        _DestVal = "INVSRCALPHA";

                        break;
                    case 7:
                        _DestVal = "DESTALPHA";

                        break;
                    case 8:
                        _DestVal = "INVDESTALPHA";

                        break;
                    case 9:
                        _DestVal = "DESTCOLOR";

                        break;
                    case 10:
                        _DestVal = "INVDESTCOLOR";

                        break;
                    case 11:
                        _DestVal = "SRCALPHASAT";

                        break;
                    case 12:
                        _DestVal = "BOTHSRCALPHA";

                        break;
                    case 13:
                        _DestVal = "BOTHINVSRCALPHA";

                        break;
                    case 14:
                        _DestVal = "BLENDFACTOR";

                        break;
                    case 15:
                        _DestVal = "INVBLENDFACTOR";

                        break;
                    case 16:
                        _DestVal = "SRCCOLOR2";

                        break;
                    case 17:
                        _DestVal = "INVSRCCOLOR2";

                        break;
                };
            }
            if (EmitterWCheckBox.Checked == true)
            {
                _WidthVal = rand.Next(1, 500);
            }
            if (EmitterHCheckBox.Checked == true)
            {
                _HeightVal = rand.Next(1, 500);
            }
            if (EmitterPosXCheckBox.Checked == true)
            {
                _XVal = rand.Next(0, 1000);
            }
            if (EmitterPosYCheckBox.Checked == true)
            {
                _YVal = rand.Next(0, 1000);
            }
            if (StartAlphaCheckBox.Checked == true)
            {
                _StartAVal = rand.Next(0, 255);
            }
            if (EndAlphaCheckBox.Checked == true)
            {
                _EndAVal = rand.Next(0, 255);
            }
            if (ParticleStartColorCheckBox.Checked == true && StartAlphaCheckBox.Checked == true)
            {
                _StartColorVal = Color.FromArgb((int)_StartAVal,rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
            }
            else if (ParticleStartColorCheckBox.Checked == true && StartAlphaCheckBox.Checked == false)
            {
                _StartColorVal = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
            }
            if (ParticleEndColorCheckBox.Checked == true && EndAlphaCheckBox.Checked == true)
            {
                _EndColorVal = Color.FromArgb((int)_EndAVal, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
            }
            else if (ParticleEndColorCheckBox.Checked == true && EndAlphaCheckBox.Checked == false)
            {
                _EndColorVal = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
            }
        }

        //private void RandomizeButton_Click(object sender, EventArgs e)
        //{
        //    if (Apply != null)
        //    {
        //        Apply(this, new ApplyEventArgs(LifeSpanNumUpDown.Value, MaxLifeNumUpDown.Value,
        //               MaxPartNumUpDown.Value, StartScaleNumUpDown.Value, EndScaleNumUpDown.Value,
        //               XVelNumUpDown.Value, XVel2NumUpDown.Value, YVelNumUpDown.Value,
        //               YVel2NumUpDown.Value, RotationNumUpDown.Value, GravityXNumUpDown.Value,
        //               GravityYNumUpDown.Value, SourceComboBox.Text, DestComboBox.Text,
        //               EmitterWNumUpDown.Value, EmitterHNumUpDown.Value, XPosNumUpDown.Value,
        //               YPosNumUpDown.Value, StartAlphaNumUpDown.Value, EndAlphaNumUpDown.Value,
        //               StartColorButton.BackColor, EndColorButton.BackColor));
        //    }
        //}
    }

        //public delegate void ApplyEventHandler(object sender, ApplyEventArgs e);

        ////decimal MinLifeVal;

        ////public decimal MinLifeVal1
        ////{
        ////    get { return MinLifeVal; }
        ////    set { MinLifeVal = value; }
        ////}
        ////decimal MaxLifeVal;

        ////public decimal MaxLifeVal1
        ////{
        ////    get { return MaxLifeVal; }
        ////    set { MaxLifeVal = value; }
        ////}
        ////decimal MaxPartVal;

        ////public decimal MaxPartVal1
        ////{
        ////    get { return MaxPartVal; }
        ////    set { MaxPartVal = value; }
        ////}
        ////decimal StartScaleVal;

        ////public decimal StartScaleVal1
        ////{
        ////    get { return StartScaleVal; }
        ////    set { StartScaleVal = value; }
        ////}
        ////decimal EndScaleVal;

        ////public decimal EndScaleVal1
        ////{
        ////    get { return EndScaleVal; }
        ////    set { EndScaleVal = value; }
        ////}
        ////decimal XVelVal;

        ////public decimal XVelVal1
        ////{
        ////    get { return XVelVal; }
        ////    set { XVelVal = value; }
        ////}

        ////decimal XVelVal2;

        ////public decimal XVelVal12
        ////{
        ////    get { return XVelVal; }
        ////    set { XVelVal = value; }
        ////}

        ////decimal YVelVal;

        ////public decimal YVelVal1
        ////{
        ////    get { return YVelVal; }
        ////    set { YVelVal = value; }
        ////}
        ////decimal YVelVal2;

        ////public decimal YVelVal12
        ////{
        ////    get { return YVelVal; }
        ////    set { YVelVal = value; }
        ////}

        ////decimal RotVal;

        ////public decimal RotVal1
        ////{
        ////    get { return RotVal; }
        ////    set { RotVal = value; }
        ////}
        ////decimal GravXVal;

        ////public decimal GravXVal1
        ////{
        ////    get { return GravXVal; }
        ////    set { GravXVal = value; }
        ////}
        ////decimal GravYVal;

        ////public decimal GravYVal1
        ////{
        ////    get { return GravYVal; }
        ////    set { GravYVal = value; }
        ////}
        ////string SrcVal;

        ////public string SrcVal1
        ////{
        ////    get { return SrcVal; }
        ////    set { SrcVal = value; }
        ////}
        ////string DestVal;

        ////public string DestVal1
        ////{
        ////    get { return DestVal; }
        ////    set { DestVal = value; }
        ////}
        ////decimal WidthVal;

        ////public decimal WidthVal1
        ////{
        ////    get { return WidthVal; }
        ////    set { WidthVal = value; }
        ////}
        ////decimal HeightVal;

        ////public decimal HeightVal1
        ////{
        ////    get { return HeightVal; }
        ////    set { HeightVal = value; }
        ////}
        ////decimal XVal;

        ////public decimal XVal1
        ////{
        ////    get { return XVal; }
        ////    set { XVal = value; }
        ////}
        ////decimal YVal;

        ////public decimal YVal1
        ////{
        ////    get { return YVal; }
        ////    set { YVal = value; }
        ////}
        ////decimal StartAVal;

        ////public decimal StartAVal1
        ////{
        ////    get { return StartAVal; }
        ////    set { StartAVal = value; }
        ////}
        ////decimal EndAVal;

        ////public decimal EndAVal1
        ////{
        ////    get { return EndAVal; }
        ////    set { EndAVal = value; }
        ////}

        ////Color StartColorVal;

        ////public Color StartColorVal1
        ////{
        ////  get { return StartColorVal; }
        ////  set { StartColorVal = value; }
        ////}
        ////Color EndColorVal;

        ////public Color EndColorVal1
        ////{
        ////  get { return EndColorVal; }
        ////  set { EndColorVal = value; }
        ////}

        //public class ApplyEventArgs : EventArgs
        //{
        //    public ApplyEventArgs(decimal _MinLifeVal, decimal _MaxLifeVal, decimal _MaxPartVal, decimal _StartScaleVal,
        //    decimal _EndScaleVal, decimal _XVelVal, decimal _XVelVal2, decimal _YVelVal, decimal _YVelVal2, decimal _RotVal,
        //    decimal _GravXVal, decimal _GravYVal, string _SrcVal, string _DestVal, decimal _WidthVal, decimal _HeightVal,
        //    decimal _XVal, decimal _YVal, decimal _StartAVal, decimal _EndAVal, Color _StartColorVal, Color _EndColorVal)
        //    {
        //        RandomizeToolBox RTB = new RandomizeToolBox();

        //        RTB.Randomize( _MinLifeVal, _MaxLifeVal, _MaxPartVal, _StartScaleVal,
        //        _EndScaleVal, _XVelVal, _XVelVal2, _YVelVal, _YVelVal2, _RotVal,
        //        _GravXVal, _GravYVal, _SrcVal, _DestVal, _WidthVal, _HeightVal,
        //        _XVal, _YVal, _StartAVal, _EndAVal, _StartColorVal, _EndColorVal);
        //    }
        //}
}